# -*- coding: iso-8859-1 -*-
# file Actuator.py
# author Rocco Martino
#
############################################################################
#    Copyright (C) 2015 by Rocco Martino                                   #
#    martinorocco@gmail.com                                                #
#                                                                          #
#    This program is free software; you can redistribute it and/or modify  #
#    it under the terms of the GNU Lesser General Public License as        #
#    published by the Free Software Foundation; either version 2.1 of the  #
#    License, or (at your option) any later version.                       #
#                                                                          #
#    This program is distributed in the hope that it will be useful,       #
#    but WITHOUT ANY WARRANTY; without even the implied warranty of        #
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         #
#    GNU Lesser General Public License for more details.                   #
#                                                                          #
#    You should have received a copy of the GNU Lesser General Public      #
#    License along with this program; if not, write to the                 #
#    Free Software Foundation, Inc.,                                       #
#    59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             #
############################################################################

############################################################################
from . import Object
import bpy
############################################################################




############################################################################
# ........................................................................ #
# ........................................................................ #
############################################################################




############################################################################
# ........................................................................ #
class Actuator(Object.Object):





############################################################################
    Object = None
############################################################################









############################################################################
    def __init__(self, obj, data, actuator):
        super(Actuator, self).__init__(actuator, data)

        self.Object = obj

        self.ClassName = "ooGame::Actuator"
        self.Name = actuator.name + "@" + obj.name
        self.CollectProps = False
        self.CheckUniqueID = True
        self.UseObjectName = False
############################################################################




############################################################################
    def writeData(self, writer):
        super(Actuator, self).writeData(writer)
############################################################################




# ........................................................................ #
############################################################################














############################################################################
# ........................................................................ #
class VisibilityActuator(Actuator):





############################################################################
    def __init__(self, obj, data, actuator):
        super(VisibilityActuator, self).__init__(obj, data, actuator)

        self.ClassName = "ooGame::VisibilityActuator"
############################################################################





############################################################################
    def writeData(self, writer):
        super(VisibilityActuator, self).writeData(writer)


        if not self.BlenderObject.use_visible:
            writer.writeLine("Visible FALSE")
############################################################################




# ........................................................................ #
############################################################################














############################################################################
# ........................................................................ #
class StateActuator(Actuator):





############################################################################
    def __init__(self, obj, data, actuator):
        super(StateActuator, self).__init__(obj, data, actuator)

        self.ClassName = "ooGame::StateActuator"
############################################################################





############################################################################
    def writeData(self, writer):
        super(StateActuator, self).writeData(writer)

        operation = self.BlenderObject.operation


        mask = 0

        for i in range ( len(self.BlenderObject.states) ):
            mask += int(self.BlenderObject.states[i]) << i


        writer.writeLine("Operation %s" % operation)
        writer.writeLine("Mask %u" % mask)
############################################################################




# ........................................................................ #
############################################################################














############################################################################
# ........................................................................ #
class MotionActuator(Actuator):





############################################################################
    def __init__(self, obj, data, actuator):
        super(MotionActuator, self).__init__(obj, data, actuator)

        self.ClassName = "ooGame::MotionActuator"
############################################################################





############################################################################
    def writeData(self, writer):
        super(MotionActuator, self).writeData(writer)

        motionType = "SIMPLE_MOTION"

        if self.BlenderObject.mode == 'OBJECT_SERVO':
            motionType = "SERVO_CONTROL"


        translation = self.BlenderObject.offset_location
        rotation = self.BlenderObject.offset_rotation
        force = self.BlenderObject.force
        torque = self.BlenderObject.torque
        linearVelocity = self.BlenderObject.linear_velocity
        angularVelocity = self.BlenderObject.angular_velocity
        translationLocal = self.BlenderObject.use_local_location
        rotationLocal = self.BlenderObject.use_local_rotation
        forceLocal = self.BlenderObject.use_local_force
        torqueLocal = self.BlenderObject.use_local_torque
        linearVelocityLocal = self.BlenderObject.use_local_linear_velocity
        angularVelocityLocal = self.BlenderObject.use_local_angular_velocity
        linearVelocityAdditive = self.BlenderObject.use_add_linear_velocity
        servoLimitX = self.BlenderObject.use_servo_limit_x
        servoLimitY = self.BlenderObject.use_servo_limit_y
        servoLimitZ = self.BlenderObject.use_servo_limit_z
        servoForceMin = [ self.BlenderObject.force_min_x, self.BlenderObject.force_min_y, self.BlenderObject.force_min_z ]
        servoForceMax = [ self.BlenderObject.force_max_x, self.BlenderObject.force_max_y, self.BlenderObject.force_max_z ]

        servoP = self.BlenderObject.proportional_coefficient
        servoI = self.BlenderObject.integral_coefficient
        servoD = self.BlenderObject.derivate_coefficient


        writer.writeLine("MotionType %s" % motionType)

        self.writeVec3Prop( writer, "Translation",      translation ) ;
        self.writeVec3Prop( writer, "Rotation",         rotation ) ;
        self.writeVec3Prop( writer, "Force",            force ) ;
        self.writeVec3Prop( writer, "Torque",           torque ) ;
        self.writeVec3Prop( writer, "LinearVelocity",   linearVelocity ) ;
        self.writeVec3Prop( writer, "AngularVelocity",  angularVelocity ) ;
        self.writeVec3Prop( writer, "ServoForceMin",    servoForceMin ) ;
        self.writeVec3Prop( writer, "ServoForceMax",    servoForceMax ) ;

        self.writeBoolProp( writer, "TranslationLocal",         translationLocal ) ;
        self.writeBoolProp( writer, "RotationLocal",            rotationLocal ) ;
        self.writeBoolProp( writer, "ForceLocal",               forceLocal ) ;
        self.writeBoolProp( writer, "TorqueLocal",              torqueLocal ) ;
        self.writeBoolProp( writer, "LinearVelocityLocal",      linearVelocityLocal ) ;
        self.writeBoolProp( writer, "AngularVelocityLocal",     angularVelocityLocal ) ;
        self.writeBoolProp( writer, "LinearVelocityAdditive",   linearVelocityAdditive ) ;
        self.writeBoolProp( writer, "ServoLimitX",              servoLimitX ) ;
        self.writeBoolProp( writer, "ServoLimitY",              servoLimitY ) ;
        self.writeBoolProp( writer, "ServoLimitZ",              servoLimitZ ) ;


        if motionType == "SERVO_CONTROL":

            writer.moveIn("PIDController TRUE")

            writer.moveIn("osgODE::PIDController")
            writer.writeLine( "UniqueID %d" % self.Data.UniqueID.generate() )
            writer.writeLine( "Name \"PIDController@%s\"" % (self.Object.name) )
            writer.writeLine( "Proportional %f" % (servoP) )
            writer.writeLine( "Integral %f" % (servoI) )
            writer.writeLine( "Derivative %f" % (servoD) )
            writer.moveOut("osgODE::PIDController")

            writer.moveOut("PIDController TRUE")
############################################################################




############################################################################
    def writeVec3Prop(self, writer, name, value):
        writer.writeLine("%s %f %f %f" %(name, value[0], value[1], value[2]))
############################################################################




############################################################################
    def writeBoolProp(self, writer, name, value):
        if value:
            writer.writeLine("%s TRUE" %(name))
        else:
            writer.writeLine("%s FALSE" %(name))
############################################################################




# ........................................................................ #
############################################################################














############################################################################
# ........................................................................ #
class PropertyActuator(Actuator):





############################################################################
    def __init__(self, obj, data, actuator):
        super(PropertyActuator, self).__init__(obj, data, actuator)

        p = self.Data.ODEObjects[obj][1]

        if p:
            p = p.getUserValue( self.BlenderObject.property )[2]

        self.ClassName = "ooGame::%sPropertyActuator" %p
############################################################################





############################################################################
    def writeData(self, writer):
        super(PropertyActuator, self).writeData(writer)

        p = self.Data.ODEObjects[self.Object][1]

        if p:
            p = p.getUserValue( self.BlenderObject.property )



        if not p:
            return



        valueType = p[2]
        mode = self.BlenderObject.mode
        prop = self.BlenderObject.property
        value = self.BlenderObject.value
        referenceProperty = self.BlenderObject.object_property



        if not value:
            value = '0'


        if valueType == "Bool":
            if value.lower().split() in [["1"], ["true"], ["on"]]:
                value = "TRUE"
            else:
                value = "FALSE"



        referenceObject = None

        if self.BlenderObject.object:
            from . import ODEObject
            referenceObject = ODEObject.createObject(self.BlenderObject.object, self.Data)





        writer.writeLine("Mode %s" % mode)
        writer.writeLine("Property \"%s\"" % prop)



        if referenceProperty:
            writer.writeLine("ReferenceProperty \"%s\"" % referenceProperty)



        if referenceObject:
            writer.moveIn("Object TRUE")

            referenceObject.writeObject(writer)

            writer.moveOut("Object TRUE")



        if value:
            writer.writeLine("Value %s" % value)
############################################################################




# ........................................................................ #
############################################################################














############################################################################
# ........................................................................ #
class SceneActuator(Actuator):





############################################################################
    def __init__(self, obj, data, actuator):
        super(SceneActuator, self).__init__(obj, data, actuator)

        self.ClassName = "ooGame::SceneActuator"
############################################################################





############################################################################
    def writeData(self, writer):
        super(SceneActuator, self).writeData(writer)

        mode = self.BlenderObject.mode

        scene = None

        try:
            scene = self.BlenderObject.scene.name
        except:
            scene = None


        writer.writeLine("Mode %s" % mode)

        if scene:
            writer.writeLine("SceneName \"%s\"" % scene)


        if mode == 'CAMERA':
            writer.writeLine( "RemoveExistingManipulator TRUE" )
############################################################################




# ........................................................................ #
############################################################################














############################################################################
# ........................................................................ #
class EditObjectActuator(Actuator):





############################################################################
    def __init__(self, obj, data, actuator):
        super(EditObjectActuator, self).__init__(obj, data, actuator)

        self.ClassName = "ooGame::EditObjectActuator"
############################################################################





############################################################################
    def writeData(self, writer):
        super(EditObjectActuator, self).writeData(writer)


        pMode = None
        pDynamicOperation = None
        pLifeTime = None
        pLinearVelocity = None
        pAngularVelocity = None
        pLinearVelocityLocal = None
        pAngularVelocityLocal = None
        pMass = None
        pRefObject = None
        pTrackTo = None
        pAngularPID = [1,0,0]
        pLinearPID = [1,0,0]
        pDistanceMin = None
        pDistanceMax = None
        pUpWorld = [0,0,1]
        pUpLocal = [0,0,1]
        pFrontLocal = [0,1,0]
        pMesh = None




        if self.BlenderObject.mode == "ADDOBJECT":
            pMode = "ADD_OBJECT"

        elif self.BlenderObject.mode == "ENDOBJECT":
            pMode = "END_OBJECT"

        elif self.BlenderObject.mode == "TRACKTO":
            pMode = "TRACK_TO"

        elif self.BlenderObject.mode == "DYNAMICS":
            pMode = "DYNAMICS"

        elif self.BlenderObject.mode == "REPLACEMESH":
            pMode = "REPLACE_MESH"



        if pMode == "DYNAMICS":
            if self.BlenderObject.dynamic_operation == "SETMASS":
                pDynamicOperation = "SET_MASS"

            elif self.BlenderObject.dynamic_operation == "ENABLERIGIDBODY":
                pDynamicOperation = "ENABLE_RIGID_BODY"

            elif self.BlenderObject.dynamic_operation == "DISABLERIGIDBODY":
                pDynamicOperation = "DISABLE_RIGID_BODY"

            elif self.BlenderObject.dynamic_operation == "SUSPENDDYN":
                pDynamicOperation = "SET_KINEMATIC"

            elif self.BlenderObject.dynamic_operation == "RESTOREDYN":
                pDynamicOperation = "SET_DYNAMIC"



        pLifeTime = self.BlenderObject.time

        pLinearVelocity = self.BlenderObject.linear_velocity
        pAngularVelocity = self.BlenderObject.angular_velocity

        if self.BlenderObject.use_local_linear_velocity:
            pLinearVelocityLocal = "TRUE"
        else:
            pLinearVelocityLocal = "FALSE"

        if self.BlenderObject.use_local_angular_velocity:
            pAngularVelocityLocal = "TRUE"
        else:
            pAngularVelocityLocal = "FALSE"



        pMass = self.BlenderObject.mass


        obj = None


        if pMode == "TRACK_TO":
            from . import ODEObject
            pTrackTo = ODEObject.createObject(self.BlenderActuator.object, self.Data)


        elif pMode == "REPLACE_MESH":
            from . import Geode, Geometry

            pMesh = Geode.Geode(None, self.Data)

            pMesh.addDrawable( Geometry.Geometry( self.BlenderObject.mesh, self.Data ) )




        elif pMode == "ADD_OBJECT":

            from . import ODEObject

            pRefObject = ODEObject.createObject( self.BlenderObject.object, self.Data )






        try:
            pAngularPID[0] = pObject["oo_%s_AP" % self.BlenderObject.name]
        except:
            pAngularPID[0] = 1.0

        try:
            pAngularPID[1] = pObject["oo_%s_AI" % self.BlenderObject.name]
        except:
            pAngularPID[1] = 0.0

        try:
            pAngularPID[2] = pObject["oo_%s_AD" % self.BlenderObject.name]
        except:
            pAngularPID[2] = 0.0



        try:
            pLinearPID[0] = pObject["oo_%s_LP" % self.BlenderObject.name]
        except:
            pLinearPID[0] = 1.0

        try:
            pLinearPID[1] = pObject["oo_%s_LI" % self.BlenderObject.name]
        except:
            pLinearPID[1] = 0.0

        try:
            pLinearPID[2] = pObject["oo_%s_LD" % self.BlenderObject.name]
        except:
            pLinearPID[2] = 0.0




        if self.BlenderObject.track_axis == "TRACKAXISX":
            pFrontLocal = [1,0,0]

        elif self.BlenderObject.track_axis == "TRACKAXISY":
            pFrontLocal = [0,1,0]

        elif self.BlenderObject.track_axis == "TRACKAXISZ":
            pFrontLocal = [0,0,1]

        elif self.BlenderObject.track_axis == "TRACKAXISNEGX":
            pFrontLocal = [-1,0,0]

        elif self.BlenderObject.track_axis == "TRACKAXISNEGY":
            pFrontLocal = [0,-1,0]

        elif self.BlenderObject.track_axis == "TRACKAXISNEGZ":
            pFrontLocal = [0,0,-1]




        if self.BlenderObject.up_axis == "UPAXISX":
            pUpWorld = [1,0,0]

        elif self.BlenderObject.up_axis == "UPAXISY":
            pUpWorld = [0,1,0]

        elif self.BlenderObject.up_axis == "UPAXISZ":
            pUpWorld = [0,0,1]



        try:
            up_local = pObject["oo_%s_up_local" % self.BlenderObject.name]

            if up_local == 0:
                pUpLocal = [1,0,0]
            elif up_local == 1:
                pUpLocal = [0,1,0]
            elif up_local == 2:
                pUpLocal = [0,0,1]
        except:
                pUpLocal = None



        try:
            pDistanceMin = pObject["oo_%s_distance_min" % self.BlenderObject.name]
        except:
            pDistanceMin = None

        try:
            pDistanceMax = pObject["oo_%s_distance_max" % self.BlenderObject.name]
        except:
            pDistanceMax = None












        writer.writeLine("Mode %s" % pMode)

        if pDynamicOperation:
            writer.writeLine("DynamicOperation %s" % pDynamicOperation)

        if pLifeTime:
            writer.writeLine("LifeTime %u" % pLifeTime)

        if pLinearVelocity:
            writer.writeLine("LinearVelocity %f %f %f" %(pLinearVelocity[0], pLinearVelocity[1], pLinearVelocity[2]))

        if pAngularVelocity:
            writer.writeLine("AngularVelocity %f %f %f" %(pAngularVelocity[0], pAngularVelocity[1], pAngularVelocity[2]))

        if pLinearVelocity:
            writer.writeLine("LinearVelocityLocal %s" %(pLinearVelocityLocal))


        if pAngularVelocity:
            writer.writeLine("AngularVelocityLocal %s" %(pAngularVelocityLocal))


        if pMass:
            writer.writeLine("Mass %f" % pMass)


        if pRefObject:

            writer.moveIn("Object TRUE")
            pRefObject.writeObject( writer )
            writer.moveOut("Object TRUE")



        if pUpWorld:
            writer.writeLine( "UpWorld %f %f %f" % (pUpWorld[0], pUpWorld[1], pUpWorld[2]) )

        if pUpLocal:
            writer.writeLine( "UpLocal %f %f %f" % (pUpLocal[0], pUpLocal[1], pUpLocal[2]) )

        if pFrontLocal:
            writer.writeLine( "FrontLocal %f %f %f" % (pFrontLocal[0], pFrontLocal[1], pFrontLocal[2]) )




        if pDistanceMin != None:
            writer.writeLine( "DistanceMin %f" % pDistanceMin )

        if pDistanceMax != None:
            writer.writeLine( "DistanceMax %f" % pDistanceMax )



        if pTrackTo:
            writer.moveIn("TrackTo TRUE")
            pTrackTo.writeObject(writer)
            writer.moveOut("TrackTo TRUE")



            writer.moveIn("LinearPID TRUE")
            writer.moveIn("osgODE::PIDController")

            writer.writeLine("UniqueID %u" % self.Data.UniqueID.generate())
            writer.writeLine("Name \"LinearPIDController@%s\"" % (pObject.name) )
            writer.writeLine("Proportional %f" % pLinearPID[0])
            writer.writeLine("Integral %f" % pLinearPID[1])
            writer.writeLine("Derivative %f" % pLinearPID[2])

            writer.moveOut("osgODE::PIDController")
            writer.moveOut("LinearPID TRUE")



            writer.moveIn("AngularPID TRUE")
            writer.moveIn("osgODE::PIDController")

            writer.writeLine("UniqueID %u" % self.Data.UniqueID.generate())
            writer.writeLine("Name \"AngularPIDController@%s\"" % (pObject.name) )
            writer.writeLine("Proportional %f" % pAngularPID[0])
            writer.writeLine("Integral %f" % pAngularPID[1])
            writer.writeLine("Derivative %f" % pAngularPID[2])

            writer.moveOut("osgODE::PIDController")
            writer.moveOut("AngularPID TRUE")



        if pMesh:
            writer.moveIn("Mesh TRUE")

            pMesh.writeObject(writer)

            writer.moveOut("Mesh TRUE")
############################################################################




# ........................................................................ #
############################################################################














############################################################################
# ........................................................................ #
class CameraActuator(Actuator):





############################################################################
    def __init__(self, obj, data, actuator):
        super(CameraActuator, self).__init__(obj, data, actuator)

        self.ClassName = "ooGame::CameraActuator"
############################################################################





############################################################################
    def writeData(self, writer):
        super(CameraActuator, self).writeData(writer)

        pTrackTo = None
        pHeight = 0.0
        pDistanceMin = 0.0
        pDistanceMax = 0.0
        pUpWorld = [0,0,1]
        pAxis = [1,0,0]
        pAngularPID = [1,0,0]
        pLinearPID = [1,0,0]


        if self.BlenderObject.object:
            from . import ODEObject
            pTrackTo = ODEObject.createObject( self.BlenderObject.object, self.Data )

        pHeight = self.BlenderObject.height
        pDistanceMin = self.BlenderObject.min
        pDistanceMax = self.BlenderObject.max
        pHeight = self.BlenderObject.height



        if self.BlenderObject.axis == "POS_X" :
            pAxis = [1, 0, 0]

        if self.BlenderObject.axis == "NEG_X" :
            pAxis = [-1, 0, 0]

        if self.BlenderObject.axis == "POS_Y" :
            pAxis = [0, 1, 0]

        if self.BlenderObject.axis == "NEG_Y" :
            pAxis = [0, -1, 0]


        pLinearPID[0] = self.BlenderObject.damping
        pAngularPID[0] = self.BlenderObject.damping



        try:
            pAngularPID[0] = pObject["oo_%s_AP" % self.BlenderObject.name]
            #pAngularPID[0] = pObject["oo_camera_AP"]
        except:
            pAngularPID[0] = 1.0

        try:
            pAngularPID[1] = pObject["oo_%s_AI" % self.BlenderObject.name]
            #pAngularPID[1] = pObject["oo_camera_AI"]
        except:
            pAngularPID[1] = 0.0

        try:
            pAngularPID[2] = pObject["oo_%s_AD" % self.BlenderObject.name]
            #pAngularPID[2] = pObject["oo_camera_AD"]
        except:
            pAngularPID[2] = 0.0



        try:
            pLinearPID[0] = pObject["oo_%s_LP" % self.BlenderObject.name]
            #pLinearPID[0] = pObject["oo_camera_LP"]
        except:
            pLinearPID[0] = 1.0

        try:
            pLinearPID[1] = pObject["oo_%s_LI" % self.BlenderObject.name]
            #pLinearPID[1] = pObject["oo_camera_LI"]
        except:
            pLinearPID[1] = 0.0

        try:
            pLinearPID[2] = pObject["oo_%s_LD" % self.BlenderObject.name]
            #pLinearPID[2] = pObject["oo_camera_LD"]
        except:
            pLinearPID[2] = 0.0



        try:
            upw = pObject["oo_%s_up_world" % self.BlenderObject.name]

            if upw == 0:
                pUpWorld = [1,0,0]
            if upw == 1:
                pUpWorld = [0,1,0]
            if upw == 2:
                pUpWorld = [0,0,1]

            if upw == 3:
                pUpWorld = [-1,0,0]
            if upw == 4:
                pUpWorld = [0,-1,0]
            if upw == 5:
                pUpWorld = [0,0,-1]
        except:
            pUpWorld = None





        if pAxis:
            writer.writeLine( "Axis %f %f %f" % (pAxis[0], pAxis[1], pAxis[2]) )


        if pUpWorld:
            writer.writeLine( "UpWorld %f %f %f" % (pUpWorld[0], pUpWorld[1], pUpWorld[2]) )


        if pDistanceMin:
            writer.writeLine( "DistanceMin %f" % pDistanceMin )


        if pDistanceMax:
            writer.writeLine( "DistanceMax %f" % pDistanceMax )


        if pHeight != None:
            writer.writeLine( "Height %f" % pHeight )



        if pTrackTo:
            writer.moveIn("TrackTo TRUE")
            pTrackTo.writeObject(writer)
            writer.moveOut("TrackTo TRUE")



            writer.moveIn("LinearPID TRUE")
            writer.moveIn("osgODE::PIDController")

            writer.writeLine("UniqueID %u" % self.Data.UniqueID.generate())
            writer.writeLine("Name \"LinearPIDController@%s\"" % (self.Object.name) )
            writer.writeLine("Proportional %f" % pLinearPID[0])
            writer.writeLine("Integral %f" % pLinearPID[1])
            writer.writeLine("Derivative %f" % pLinearPID[2])

            writer.moveOut("osgODE::PIDController")
            writer.moveOut("LinearPID TRUE")



            writer.moveIn("AngularPID TRUE")
            writer.moveIn("osgODE::PIDController")

            writer.writeLine("UniqueID %u" % self.Data.UniqueID.generate())
            writer.writeLine("Name \"AngularPIDController@%s\"" % (self.Object.name) )
            writer.writeLine("Proportional %f" % pAngularPID[0])
            writer.writeLine("Integral %f" % pAngularPID[1])
            writer.writeLine("Derivative %f" % pAngularPID[2])

            writer.moveOut("osgODE::PIDController")
            writer.moveOut("AngularPID TRUE")
############################################################################




# ........................................................................ #
############################################################################














############################################################################
# ........................................................................ #
class MessageActuator(Actuator):





############################################################################
    def __init__(self, obj, data, actuator):
        super(MessageActuator, self).__init__(obj, data, actuator)

        self.ClassName = "ooGame::MessageActuator"
############################################################################





############################################################################
    def writeData(self, writer):
        super(MessageActuator, self).writeData(writer)

        pTarget = None
        pType = "TEXT"
        pSubject = None


        if self.BlenderObject.to_property:
            from . import ODEObject
            pTarget = ODEObject.createObject( bpy.data.objects[self.BlenderObject.to_property], self.Data )


        pType = "TEXT"
        pSubject = self.BlenderObject.subject


        writer.writeLine("Type %s" % pType)

        if pSubject:
            writer.writeLine("Subject \"%s\"" % pSubject)


        if pTarget:
            writer.moveIn("Target TRUE")
            pTarget.writeObject(writer)
            writer.moveOut("Target TRUE")
############################################################################




# ........................................................................ #
############################################################################














############################################################################
# ........................................................................ #
class GameActuator(Actuator):





############################################################################
    def __init__(self, obj, data, actuator):
        super(GameActuator, self).__init__(obj, data, actuator)

        self.ClassName = "ooGame::GameActuator"
############################################################################





############################################################################
    def writeData(self, writer):
        super(GameActuator, self).writeData(writer)

        pFileName = None
        pMode = None

        pFileName = self.BlenderObject.filename


        if self.BlenderObject.mode == "QUIT" :
            pMode = "QUIT"

        elif self.BlenderObject.mode == "RESTART" :
            pMode = "RESTART"

        elif self.BlenderObject.mode == "START" :
            pMode = "START_FROM_FILE"

        else:
            pMode = "USER"



        writer.writeLine("Mode %s" % pMode)


        if pFileName:
            writer.writeLine("FileName \"%s\"" % pFileName)
############################################################################




# ........................................................................ #
############################################################################














############################################################################
# ........................................................................ #
class MouseActuator(Actuator):





############################################################################
    def __init__(self, obj, data, actuator):
        super(MouseActuator, self).__init__(obj, data, actuator)

        self.ClassName = "ooGame::MouseActuator"
############################################################################





############################################################################
    def writeData(self, writer):
        super(MouseActuator, self).writeData(writer)

        pMode = None

        pUseAxisX = None
        pSensitivityX = None
        pThresholdX = None
        pMinX = None
        pMaxX = None
        pObjectAxisX = None
        pLocalX = None
        pResetX = None

        pUseAxisY = None
        pSensitivityY = None
        pThresholdY = None
        pMinY = None
        pMaxY = None
        pObjectAxisY = None
        pLocalY = None
        pResetY = None




        pMode = self.BlenderObject.mode



        try:
            if self.Object["oo_%s_move" % self.BlenderObject.name] != 0:
                pMode = "MOVE"
        except:
            pMode = self.BlenderObject.mode



        pSensitivityX = self.BlenderObject.sensitivity_x
        pThresholdX = self.BlenderObject.threshold_x
        pMinX = self.BlenderObject.min_x
        pMaxX = self.BlenderObject.max_x

        if self.BlenderObject.use_axis_x:
            pUseAxisX = "TRUE"
        else:
            pUseAxisX = "FALSE"

        if self.BlenderObject.local_x:
            pLocalX = "TRUE"
        else:
            pLocalX = "FALSE"

        if self.BlenderObject.reset_x:
            pResetX = "TRUE"
        else:
            pResetX = "FALSE"

        if self.BlenderObject.object_axis_x == "OBJECT_AXIS_X":
            pObjectAxisX = "1 0 0"
        elif self.BlenderObject.object_axis_x == "OBJECT_AXIS_Y":
            pObjectAxisX = "0 1 0"
        elif self.BlenderObject.object_axis_x == "OBJECT_AXIS_Z":
            pObjectAxisX = "0 0 1"



        pSensitivityY = self.BlenderObject.sensitivity_y
        pThresholdY = self.BlenderObject.threshold_y
        pMinY = self.BlenderObject.min_y
        pMaxY = self.BlenderObject.max_y

        if self.BlenderObject.use_axis_y:
            pUseAxisY = "TRUE"
        else:
            pUseAxisY = "FALSE"

        if self.BlenderObject.local_y:
            pLocalY = "TRUE"
        else:
            pLocalY = "FALSE"

        if self.BlenderObject.reset_y:
            pResetY = "TRUE"
        else:
            pResetY = "FALSE"

        if self.BlenderObject.object_axis_y == "OBJECT_AXIS_X":
            pObjectAxisY = "1 0 0"
        elif self.BlenderObject.object_axis_y == "OBJECT_AXIS_Y":
            pObjectAxisY = "0 1 0"
        elif self.BlenderObject.object_axis_y == "OBJECT_AXIS_Z":
            pObjectAxisY = "0 0 1"






        writer.writeLine("Mode %s" % pMode)


        writer.writeLine("UseAxisX %s" %pUseAxisX)
        writer.writeLine("SensitivityX %f" %pSensitivityX)
        writer.writeLine("ThresholdX %f" %pThresholdX)

        if pMinX:
            writer.writeLine("MinX %f" %pMinX)

        if pMaxX:
            writer.writeLine("MaxX %f" %pMaxX)

        writer.writeLine("ObjectAxisX %s" %pObjectAxisX)
        writer.writeLine("LocalX %s" %pLocalX)
        writer.writeLine("ResetX %s" %pResetX)


        writer.writeLine("UseAxisY %s" %pUseAxisY)
        writer.writeLine("SensitivityY %f" %pSensitivityY)
        writer.writeLine("ThresholdY %f" %pThresholdY)

        if pMinY:
            writer.writeLine("MinY %f" %pMinY)

        if pMaxY:
            writer.writeLine("MaxY %f" %pMaxY)

        writer.writeLine("ObjectAxisY %s" %pObjectAxisY)
        writer.writeLine("LocalY %s" %pLocalY)
        writer.writeLine("ResetY %s" %pResetY)
############################################################################




# ........................................................................ #
############################################################################
